#!/bin/sh

config_dir="/etc/step-ca"
log_dir="/var/log/step-ca"

addgroup -S step-ca 2>/dev/null
adduser -S -D -h ${config_dir} -s /bin/sh -G step-ca \
	-g "step-ca user" step-ca 2>/dev/null

directory_list="config db"
for directory in $directory_list; do
	mkdir -p ${config_dir}/"$directory"
done
mkdir ${log_dir}

step_path_profile="STEPPATH=\"${config_dir}\"; export STEPPATH"
if [ ! -f ${config_dir}/.profile ]; then
	echo "$step_path_profile" > ${config_dir}/.profile
else
	echo "$step_path_profile" >> ${config_dir}/.profile
fi

chown -R step-ca:step-ca ${config_dir}
chmod -R 700 ${config_dir}

chown -R step-ca:step-ca ${log_dir}

exit 0
